import React, { Suspense } from "react";
import routes from "./router_config";
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
function index() {
  const renderRouter = (arr) => {
    console.log(arr);
    return arr.map((item, index) => {
      return item.path ? (
        <Route
          key={index}
          path={item.path}
          element={<item.element></item.element>}
        >
          {item.children && renderRouter(item.children)}
        </Route>
      ) : (
        <Route
          key={index}
          path={item.from}
          element={<Navigate to={item.to}></Navigate>}
        />
      );
    });
  };
  return (
    <Suspense fallback={<div>loding...</div>}>
      <BrowserRouter>
        <Routes>{renderRouter(routes)}</Routes>
      </BrowserRouter>
    </Suspense>
  );
}
export default index;
